package com.pengke.pangu.service.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;

/**
 *   用此版本进行代码生成
 */
public class CodeGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://118.89.81.147:3306/pangu?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true", "root", "pangu@xuzhou")
                .globalConfig(builder -> builder
                        .author("lijunjie")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/pangu-service/src/main/java")
                        .enableSpringdoc()
                        .dateType(DateType.ONLY_DATE)
                )
                .packageConfig(builder -> builder
                        .parent("com.pengke.pangu.service.sys")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .controller("")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .addInclude("sys_log")
                        .entityBuilder()
                        .logicDeletePropertyName("deleted")
                        .enableLombok()
                        .enableTableFieldAnnotation()
                        .naming(NamingStrategy.underline_to_camel)
                        .columnNaming(NamingStrategy.underline_to_camel)
                        .controllerBuilder().disable()
                        .mapperBuilder()
                        .enableBaseColumnList() // 启用 columnList (通用查询结果列)
                        .enableBaseResultMap() // 启动resultMap
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
